package com.ycsj.goldmedalnewconcept.student.activity;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import com.ycsj.common.base.BaseActivity;
import com.ycsj.common.base.BusInfo;
import com.ycsj.common.base.SpKeys;
import com.ycsj.common.utils.SPUtil;
import com.ycsj.common.utils.UiUtils;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.common.Constants;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 学生端--宠物领取第三页
 * Created by Kevin on 2019/2/28
 */

public class StudentGetpetThreeActivity extends BaseActivity {

    @BindView(R.id.iv_btn)
    ImageView iv_btn;
    @BindView(R.id.iv_pet)
    ImageView iv_pet;
    @BindView(R.id.iv_flower1)
    ImageView iv_flower1;
    @BindView(R.id.iv_flower2)
    ImageView iv_flower2;
    @BindView(R.id.iv_flower3)
    ImageView iv_flower3;

    //控件做动画的集合
    private AnimatorSet animatorSet;

    @Override
    protected int getContentLayout() {
        return R.layout.activity_student_getpet_three;
    }

    @Override
    protected void init() {

        initStateBar();

        //初始化宠物形象
        initPet();

        //初始化动画
        initAnim();
    }


    /**
     * 初始化动画
     */
    private void initAnim() {

        ObjectAnimator xOneAnim = ObjectAnimator.ofFloat(iv_flower1, "alpha", 1, 0, 1);
        ObjectAnimator xTwoAnim = ObjectAnimator.ofFloat(iv_flower2, "alpha", 1, 0, 1);
        ObjectAnimator xThreeAnim = ObjectAnimator.ofFloat(iv_flower3, "alpha", 1, 0, 1);

        xOneAnim.setRepeatCount(ValueAnimator.INFINITE);
        xOneAnim.setRepeatMode(ValueAnimator.RESTART);
        xOneAnim.setDuration(4000);

        xTwoAnim.setRepeatCount(ValueAnimator.INFINITE);
        xTwoAnim.setRepeatMode(ValueAnimator.RESTART);
        xTwoAnim.setDuration(4500);

        xThreeAnim.setRepeatCount(ValueAnimator.INFINITE);
        xThreeAnim.setRepeatMode(ValueAnimator.RESTART);
        xThreeAnim.setDuration(5000);

        animatorSet = new AnimatorSet();

        animatorSet.playTogether(xOneAnim, xTwoAnim, xThreeAnim);

        animatorSet.setInterpolator(new LinearInterpolator());

        animatorSet.start();

    }

    /**
     * 初始化宠物形象
     */
    private void initPet() {

        String type = SPUtil.getString(this, SpKeys.PETTYPE);

        switch (type) {
            case "1":
                //老虎
                iv_pet.setImageResource(R.drawable.student_choosepet_tiger);
                break;
            case "2":
                //大象
                iv_pet.setImageResource(R.drawable.student_choosepet_elephant);
                break;
            case "3":
                //狗
                iv_pet.setImageResource(R.drawable.student_choosepet_dog);
                break;
            case "4":
                //怪物
                iv_pet.setImageResource(R.drawable.student_choosepet_monster);
                break;
        }
    }

    /**
     * 页面控件的点击事件
     *
     * @param v
     */
    @OnClick({R.id.iv_btn})
    public void onViewClick(View v) {
        switch (v.getId()) {
            case R.id.iv_btn:
                //确定按钮
                UiUtils.startActivity(this, StudentGetpetFourActivity.class);
                break;
        }
    }

    /**
     * 事件处理
     *
     * @param busInfo
     */
    @Override
    public void busEvent(BusInfo busInfo) {
        super.busEvent(busInfo);
        if (busInfo != null && Constants.CLOSEPETPAGE == busInfo.type) {
            finish();
        }
    }
}
